package Test;

import java.util.Arrays;
import java.util.Scanner;

public class Main04 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = scanner.nextInt();
        }
        Arrays.sort(l);
        int ans;
        int temp = l.length / 2;
        if (l.length % 2 == 0) {
            for (int i = 0; i < temp; i++) {
                l[i] += m;
            }
            for (int i = temp; i < l.length; i++) {
                l[i] -= m;
            }
        } else {
            for (int i = 0; i < temp; i++) {
                l[i] += m;
            }
            for (int i = temp + 1; i < l.length; i++) {
                l[i] -= m;
            }
        }
        Arrays.sort(l);
        System.out.println(l[l.length - 1] - l[0]);

    }
}
